/*
 * $Id: AddToSourceControlActionDelegate.java 38 2002-10-13 09:51:26Z bpruessmann $
 * 
 * Copyright (c) 2001,2002 Boris Pruessmann and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *    Boris Pruessmann - Initial implementation.
 */
package net.sourceforge.perforce.ui.action;

import org.eclipse.core.resources.IResource;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;

/**
  * Part of the Perforce ActionSet.
  * 
  * @version $Revision: 38 $
  * @author  <a href="mailto:bpruessmann@users.sourceforge.net">Boris Pruessmann</a>
  * 
  * TODO: Fix retargeting
  */
public class AddToSourceControlActionDelegate extends AddToSourceControlAction
	implements IWorkbenchWindowActionDelegate
{
	// --------------------------------------------------------------------------- Private Variables
	
	/** Stores the WorkbenchWindow instance. */
	private IWorkbenchWindow window;

	// ------------------------------------------------------------------------------ Public Methods

	/** @see IWorkbenchWindowActionDelegate#init(IWorkbenchWindow) */
	public void init(IWorkbenchWindow window)
	{
		this.window = window;
	}

	/** @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() */
	public void dispose()
	{
		this.window = null;
	}

	// --------------------------------------------------------------------------- Protected Methods

	/** @see TeamAction#getSelectedResources() */
	protected IResource[] getSelectedResources()
	{
		IWorkbenchPage page = window.getActivePage();
		IEditorPart editor = page.getActiveEditor();
		if (editor != null)
		{
			IEditorInput input = editor.getEditorInput();
			if (input instanceof IFileEditorInput)
			{
				return new IResource[] { ((IFileEditorInput) input).getFile() };
			}
		}
		
		return new IResource[0];
	}	
}
